package zgc.demo.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zgc.demo.provider.entity.Goods;
import zgc.demo.provider.service.GoodsService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;
    @Value("${server.port}")
    private String port;

    @GetMapping("/getGoodsById/{goodsId}")
    public Map<String, Goods> getGoodsById(@PathVariable("goodsId") String goodsId,String username) {
        System.out.println(username);
        Map<String, Goods> map = new HashMap<>();
        Goods goods = goodsService.getGoodsById(goodsId);
        map.put(port, goods);
        return map;
    }

    @GetMapping("/getGoods")
    public List<Goods> getGoodsById() {
        List<Goods> goods = goodsService.getGoods();
        return goods;
    }

}
